package com.fishingwithme.infrastructure.dtos;

import cn.fishingwithme.domain.spots.*;
import com.fishingwithme.domain.spots.*;
import com.fishingwithme.infrastructure.utils.CommonUtils;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.databind.node.ObjectNode;
import lombok.Data;

import java.util.Date;
import java.util.List;

@Data
public class UserSpotDto {
    private Long fisherId;
    private Long spotId;
    private String city;
    private String cityCode;
    private Double longitude;
    private Double latitude;
    private String name;
    private Boolean isFree;
    private WaterType waterType;
    private SpotLvl lvl;

    private Boolean collected;
    @JsonIgnore
    private String spotTypes;
    private List<ObjectNode> jsonSpotTypes;
    @JsonIgnore
    private String fishTypes;
    private List<ObjectNode> jsonFishTypes;

    private Boolean isParkingEasy;
    private ParkingDistance distance;
    @JsonIgnore
    private String pictures;
    private List<String> jsonPics;

    private Boolean isPrivate;
    private Long createdBy;
    private String nickName;
    private String avatarUrl;
    private Date updatedAt;
    private String description;
    private Boolean isForbidden;
    private Integer creditVal;

    // 关联对象：统计信息
    private SpotStatisticsDto statistics;

    // 关联集合：访问历史
    private List<SpotVisitHisDto> visitHis;


    public UserSpotDto format() {
        this.setJsonSpotTypes(CommonUtils.convert(this.getSpotTypes(), SpotType.class));
        this.setJsonPics(CommonUtils.convert(this.getPictures(), String.class));
        this.setJsonFishTypes(CommonUtils.convert(this.getFishTypes(), FishType.class));
        this.visitHis = this.visitHis.stream().map(SpotVisitHisDto::format).collect(java.util.stream.Collectors.toList());
        return this;
    }
}

